package com.spc.car.data.domain.project.po;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.spc.car.common.utils.StringUtils;
import com.spc.car.data.entity.project.ProjectTendering;
import com.spc.car.data.util.PageParam;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Date;

@Data
@Accessors(chain = true)
public class QueryProjectTenderingPO<T> extends PageParam<T> {

    private String projectName;

    private Long projectDepId;

    private Long projectManagerId;

    /**
     * 开始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:dd")
    private Date beginTime;

    /**
     * 结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:dd")
    private Date endTime;

    public Wrapper toWrapper() {
        QueryWrapper<ProjectTendering> wrapper =
                new QueryWrapper<ProjectTendering>()
                        .like(StringUtils.isNotBlank(this.projectName), "project_name", this.projectName)

                        .eq(ObjectUtils.isNotNull(this.projectDepId), "project_dep_id", this.projectDepId)

                        .eq(ObjectUtils.isNotNull(this.projectManagerId), "project_manager_id", this.projectManagerId)

                        .ge(ObjectUtils.isNotNull(this.beginTime), "create_time", this.beginTime)

                        .le(ObjectUtils.isNotNull(this.endTime), "create_time", this.endTime)

                        .orderByDesc("create_time");

        return wrapper;
    }
}
